<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>上传国家视频和国歌</title>
    <%@ include file="/WEB-INF/include/commoncss.jsp"%>
    <script type="text/javascript"
            src="${ctx}/javascript/laydate/laydate.js"></script>
    <%@ include file="/WEB-INF/include/commonjs.jsp"%>
</head>
<body>
<span style="display:inline-block;margin: 50px auto 20px;border-top: solid 1px #999999;width: 45%"></span><span style="color: #999999;font-size: 16px;">上传国家视频</span><span style="display:inline-block;margin: 50px auto 20px;border-bottom: solid 1px #999999;width: 45%"></span>
<div action="" class="form form-horizontal" id="scheduleAdd">
    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-2"><span
                class="c-red">*</span>国家中文名：</label>
        <div class="formControls col-xs-8 col-sm-3">
            <input id="nation_z" name="nation_z" value="日本" class="input-text"/>
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-2"><span
                class="c-red">*</span>视频名称：</label>
        <div class="formControls col-xs-8 col-sm-3">
            <input id="title_video" name="title_video" value="日本宣传视频" class="input-text"/>
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-2"><span
                class="c-red">*</span>上传视频：</label>
        <%--//带文本框--%>
        <div class="formControls">
        <span class="btn-upload form-group" style="margin-left: 15px;">
                <input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-1" readonly><a  class="btn btn-primary radius"><i class="Hui-iconfont">&#xe642;</i> 选择文件</a>
               <input type="file" multiple name="file-1" class="input-file" id="uploadFiles">
        </span>
        </div>
    </div>
    <div class="row cl">
        <label class="form-label col-xs-4 col-sm-5"><span style="color:#999999;font-size: 16px;"><span class="c-red">*</span>(可以多视频上传，但每个视频不能超多100M的大小)</span></label>
    </div>
    <div class="row cl">
            <button type="button" class="btn btn-success radius" style="width: 20%;margin-left: 55px;background-color: #6495ED;border-color: #6495ED;" onClick="update_files()">上传</button>
    </div>
</div>


<script>
    function update_files(){
//
        var nation_z=$("#nation_z").val();
        var title_video=$("#title_video").val();

        var formData=new FormData();
        for(var i=0;i<$("#uploadFiles")[0].files.length;i++){
            formData.append("nation_files",$("#uploadFiles")[0].files[i]);
        }

        formData.append("nation_z",nation_z);
        formData.append("title_video",title_video);
//        alert("works");
        var urlLink="${ctx}/UploadAllFiles/uploadNationFile_videos.do";
        $.ajax({
            url:urlLink,
            type:"post",
            data: formData,
            async:false,
            xhrFields: {
                withCredentials: true
            },
            cache: false,
            contentType: false,
            processData: false,
            // dataType : "json",
            scriptCharset: 'utf-8',
            success:function (data) {
                if(data=="上传成功"){
                    layer.msg(data,{icon:1,time:2000},function(){
                        parent.location.reload(true);
                    })
                }else{
                    layer.msg(data,{icon:2,time:2000});
                }
            },
            error:function (data) {
                alert("服务器处理失败！");
            }
        })//ajax
    }
</script>
</article>

<span style="display:inline-block;margin: 50px auto 20px;border-top: solid 1px #999999;width: 45%"></span><span style="color: #999999;font-size: 16px;">上传国歌</span><span style="display:inline-block;margin: 50px auto 20px;border-bottom: solid 1px #999999;width: 45%"></span>
<%--国歌---------------------------------------------%>
<article class="page-container">
    <div action="" class="form form-horizontal">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span
                    class="c-red">*</span>上传国歌：</label>
            <%--带文本框--%>
            <span class="btn-upload form-group">
                <input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-2" readonly><a  class="btn btn-primary radius"><i class="Hui-iconfont">&#xe642;</i> 选择文件</a>
                <input type="file" name="file-1" class="input-file" id="uploadFile">
            </span>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-9"><span style="color:#999999;font-size: 16px;"><span class="c-red">*</span>(命名规范：nationalSongs.zip，国歌以国家的中文名称命名，如果命名不规范会导致上传失败)</span></label>
        </div>
        <div class="row cl">
            <button value="" type="button" class="btn btn-success radius" style="width: 20%;margin-left: 55px;background-color: #6495ED;border-color: #6495ED;" onClick="upload_ZIP()">上传</button>
        </div>
    </div>

    <script>
        //上传文件
        function upload_ZIP() {
            var urlLink="${ctx }/BaseInformation/uploadNationFile.do";

            var fileValue=$("#uploadFile").val();
            var fileName=getFileName(fileValue);
            var selectFileKind=4;

            if (fileName != "nationalSongs"){
                alert("上传文件命名不规范，请重新命名")
                return false;
            }else{
                var formData=new FormData();
                formData.append("nation_file",$("#uploadFile")[0].files[0]);
                formData.append("selectFileKind",selectFileKind);
                $.ajax({
                    url:urlLink,
                    type:"post",
                    data: formData,
                    async:false,
                    xhrFields: {
                        withCredentials: true
                    },
                    cache: false,
                    contentType: false,
                    processData: false,
                    // dataType : "json",
                    scriptCharset: 'utf-8',
                    // contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    success:function (data) {
                        if(data=="上传成功"){
                            layer.msg(data,{icon:1,time:2000},function(){
                                parent.location.reload(true);
                            })
                        }else{
                            layer.msg(data,{icon:2,time:2000});
                        }

                    },
                    error:function (data) {
                        alert("服务器处理失败！");
                    }
                })//ajax
            }
        }

        //    获取文件名
        function getFileName(fileValue) {
            var strFileName=fileValue.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1");  //正则表达式获取文件名，不带后缀
            var FileExt=fileValue.replace(/.+\./,"");   //正则表达式获取后缀
            return strFileName;
        }
        //    判断命名规范
        function judgeNameIsRight(fileName,index) {
            if (fileName != rightName[index-1] || fileName==null || fileName==""){
                return false;
            }else{
                return true;
            }
        }
        var rightName=["nationalSongs"];
    </script>
</article>

<span style="display:inline-block;margin: 50px auto 20px;border-top: solid 1px #999999;width: 45%"></span><span style="color: #999999;font-size: 16px;">上传区位地图</span><span style="display:inline-block;margin: 50px auto 20px;border-bottom: solid 1px #999999;width: 45%"></span>
<%--区位地图---------------------------------------------%>
<article class="page-container">
    <div action="" class="form form-horizontal">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span
                    class="c-red">*</span>上传区位地图：</label>
            <%--带文本框--%>
            <span class="btn-upload form-group">
                <input class="input-text upload-url radius" type="text" name="uploadfile-1" id="uploadfile-3" readonly><a  class="btn btn-primary radius"><i class="Hui-iconfont">&#xe642;</i> 选择文件</a>
                <input type="file" name="file-1" class="input-file" id="uploadMapPicture">
            </span>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-9"><span style="color:#999999;font-size: 16px;"><span class="c-red">*</span>(命名规范：locationMaps.zip，区位地图以国家的中文名称命名，如果命名不规范会导致上传失败)</span></label>
        </div>
        <div class="row cl">
            <button value="" type="button" class="btn btn-success radius" style="width: 20%;margin-left: 55px;background-color: #6495ED;border-color: #6495ED;" onClick="upload_ZIP1()">上传</button>
        </div>
    </div>

    <script>
        //上传文件
        function upload_ZIP1() {
            var urlLink="${ctx }/BaseInformation/uploadNationFile.do";

            var fileValue=$("#uploadMapPicture").val();
            var fileName=getFileName(fileValue);
            var selectFileKind=1;

            if (fileName != "locationMaps"){
                alert("上传文件命名不规范，请重新命名")
                return false;
            }else{
                var formData=new FormData();
                formData.append("nation_file",$("#uploadMapPicture")[0].files[0]);
                formData.append("selectFileKind",selectFileKind);
                $.ajax({
                    url:urlLink,
                    type:"post",
                    data: formData,
                    async:false,
                    xhrFields: {
                        withCredentials: true
                    },
                    cache: false,
                    contentType: false,
                    processData: false,
                    // dataType : "json",
                    scriptCharset: 'utf-8',
                    // contentType: "application/x-www-form-urlencoded; charset=utf-8",
                    success:function (data) {
                        if(data=="上传成功"){
                            layer.msg(data,{icon:1,time:2000},function(){
                                parent.location.reload(true);
                            })
                        }else{
                            layer.msg(data,{icon:2,time:2000});
                        }

                    },
                    error:function (data) {
                        alert("服务器处理失败！");
                    }
                })//ajax
            }
        }

        //    获取文件名
        function getFileName(fileValue) {
            var strFileName=fileValue.replace(/^.+?\\([^\\]+?)(\.[^\.\\]*?)?$/gi,"$1");  //正则表达式获取文件名，不带后缀
            var FileExt=fileValue.replace(/.+\./,"");   //正则表达式获取后缀
            return strFileName;
        }
        //    判断命名规范
        function judgeNameIsRight(fileName,index) {
            if (fileName != rightName[index-1] || fileName==null || fileName==""){
                return false;
            }else{
                return true;
            }
        }
        var rightName=["nationalSongs"];
    </script>
</article>
</body>

</html>